<?php
namespace api\modules\v1\controllers;
use api\common\controllers\UserController as U;
use yii\web\HttpException;
use yii\web\ServerErrorHttpException;
use Yii;

class ReportController extends U
{
    public $modelClass = 'api\modules\v1\models\Report';

    public function actions()
    {
        $actions = parent::actions();
        unset($actions['index'],$actions['update'], $actions['create'], $actions['delete'], $actions['view']); //卸载操作
        return $actions;
    }


    /*
     * 屏蔽信息
     * @return array
     * @throws HttpException
     * @throws ServerErrorHttpException
     */
    public function actionCreate(){
        $model = new $this->modelClass();
        $model->attributes = Yii::$app->request->post();
        if($model->report()){
            return [
                "message"=>"举报成功!",
            ];
        }elseif (!$model->hasErrors()) {
            throw new ServerErrorHttpException('由于不明原因未能创建对象.');
        }else{
            throw new HttpException(401,array_values($model->getFirstErrors())[0],0);
        }
    }



}